import 'package:flutter/material.dart';

//数字滚动
class ZdyRollingTextAnimation extends StatefulWidget {
  int rollingTextValue;
  Color rollingTextColor;

  ZdyRollingTextAnimation({
    this.rollingTextValue,
    this.rollingTextColor = const Color(0xffED9CBE),
  });

  @override
  _ZdyRollingTextAnimationState createState() =>
      _ZdyRollingTextAnimationState();
}

class _ZdyRollingTextAnimationState extends State<ZdyRollingTextAnimation>
    with SingleTickerProviderStateMixin {
  //控制器
  AnimationController _animationController;
  Animation<double> _animation;

  @override
  void initState() {
    super.initState();

    _animationController =
        AnimationController(duration: Duration(milliseconds: 300), vsync: this);

    _animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
        parent: _animationController,
        curve: Interval(1 / 9, 1.0, curve: Curves.easeOut)));

    _animationController.forward();
  }

  @override
  void dispose() {
    _animationController.dispose();
    // TODO: implement dispose
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: _animationController,
      builder: (context, widget) {
        return FadeTransition(
          opacity: _animation,
          child: Container(
              color: Colors.purple,
              height: 30,
              width: double.infinity,
              child: Text(
                "${(this.widget.rollingTextValue * _animation.value).toInt()}",
                style: TextStyle(
                    color: this.widget.rollingTextColor, fontSize: 20),
              )),
        );
      },
    );
  }
}
